<?php

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use frontend\models\FenhuiForm;

$this->title = '申请分会';
$this->params['breadcrumbs'][] = $this->title;
?>
<style>
    .bo{background: #FFF;}
 </style>
<section class="formbox" style="background: #FFF;">
	<form  action="<?= yii\helpers\Url::to(['member/apply_association']);?>" enctype="multipart/form-data" id="subform" method='post'>
		<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
	            <div class="textlines">
	            	<ul>
	            		<li><span class="boxtt">企业名称：</span><input style="width: 3.2rem;" type="text" id="company" name="company" value="<?= $member['company'] ?>" placeholder="请输入企业名称"/><span class="xing" style="float:right; margin-right:0.2rem;">*</span></li>
	            		<li><span class="boxtt">企业所在地：</span>
	            			<span style=" float: left; height: 0.8rem;">
	            				<select id="province" value="<?= $member['loc_province'] ?>"  name="loc_province" style=" font-size: 0.22rem; margin-left:0.2rem; "></select>
							    <select id="city" value="<?= $member['loc_city'] ?>"  name="loc_city" style="font-size: 0.22rem;  margin-left: -

0.25rem;"></select>
							    <select id="area" value="<?= $member['loc_town'] ?>" name="loc_town" style="font-size: 0.22rem; margin-left: -0.25rem;"></select>
	            			</span>
	            			<span class="xing" style="float:right; margin-right:0.2rem;">*</span></li>
                        <li><span class="boxtt">企业详细地址：</span><input style="width: 3.2rem;" type="text" id="address" name="address" value="<?= $member['address'] ?>"  placeholder="请输入企业详细地址"/><span class="xing" style="float:right; margin-right:0.2rem;">*</span></li>
                        
                        <li><span class="boxtt">企业电话：</span><input style="width: 3.2rem;" type="text" id="farentel" name="farentel" value="<?= $member['farentel'] ?>" placeholder="请输入企业电话"/><span class="xing" style="float:right; margin-right:0.2rem;">*</span></li>
                        
                        <li><span class="boxtt">员工总数(人)：</span><input style="width: 3.2rem;" type="text" id="grnum" name="grnum" value="<?= $member['grnum'] ?>"  placeholder="请输入员工总数"/></li>
                        
                        <li><span class="boxtt">注册资金(万元)：</span><input style="width: 3.2rem;" type="text" id="zhucezj" name="zhucezj" value="<?= $member['zhucezj'] ?>" placeholder="请输入企业注册资金"/><span class="xing" style="float:right; margin-right:0.2rem;">*</span></li>
                        
                        <li><span class="boxtt">联系人姓名：</span><input style="width: 3.2rem;" type="text" id="faren" name="faren" value="<?= $member['faren'] ?>" placeholder="请输入联系人姓名"/><span class="xing" style="float:right; margin-right:0.2rem;">*</span></li>
                        
                        <li><span class="boxtt">联系人电话：</span><input style="width: 3.2rem;" type="text" id="farenphone" name="farenphone" value="<?= $member['farenphone'] ?>" placeholder="请输入联系人电话"/><span class="xing" style="float:right; margin-right:0.2rem;">*</span></li>
	            		
                        <li><span class="boxtt">电子邮箱：</span><input style="width: 3.2rem;" type="text" id="farenemail" name="farenemail" value="<?= $member['farenemail'] ?>" placeholder="请输入联系人电子邮箱"/><span class="xing" style="float:right; margin-right:0.2rem;">*</span></li>
	            	</ul>
	            </div>
		        <input type="hidden" name="step"  value="1" />
	            <div class="buzhou"><a href="/member/apply" class="upbtn">上一步</a><button id="sub" class="nextbtn" type="submit">下一步</button></div>
	</form>


</section>
			
<script>
$(document).ready(function() {
  $("#sub").click(function(){

       var company = $("#company").val();
       var address = $("#address").val();
       var farentel = $("#farentel").val();
       var grnum = $("#grnum").val();
       var zhucezj = $("#zhucezj").val();
       var faren = $("#faren").val();
       var farenphone = $("#farenphone").val();
       var farenemail = $("#farenemail").val();

       var isNum = /^[0-9]+.?[0-9]*$/;
       var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/;
       var tel_check  = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
       var email_check  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

     
       if(company==""){
          alert("请填写企业名称！");
          return false;
         }
      
       if(($('#province').text())==""){
          alert("请选择省！");
          return false;
         }
       if(($('#province').text())==""){
          alert("请选择市！");
          return false;
         }
       if(($('#area').text())==""){
          alert("请选择地区！");
          return false;
         }
      
       if(address==""){
          alert("请填写企业详细地址！");
        return false;
         }
         
       if(farentel=="") {
          alert("请填写企业电话！");
        return false;
         }
        if(tel_check.test(farentel) || isPhone.test(farentel)) {

        } else {
          alert("企业电话格式不正确！");
          return false;
        }

       if(grnum==""){
          alert("请填写员工总数！");
        return false;
         }
       if(!isNum.test(grnum)){
          alert("员工总数格式不正确！");
        return false;
         }


       if(zhucezj==""){
          alert("请填写注册资金！");
        return false;
         }
         
        if(!isNum.test(zhucezj)){
          alert("注册资金格式不正确！");
        return false;
         }

       if(faren==""){
          alert("请填写联系人姓名！");
        return false;
         }
         
       if(farenphone=="") {
          alert("请填写联系人电话！");
        return false;
         } else {
            if(!tel_check.test(farenphone)){
                  alert("联系人电话格式不正确！");
                  return false;
              }
        }
         
       if(farenemail==""){
            alert("请填写电子邮箱！");
            return false;
        } else {
            if(!email_check.test(farenemail)){
                  alert("电子邮箱格式不正确！");
                  return false;
              }
        }
         
        $('#subform').submit();  
    })
    
}) ;
</script>
<script type="text/javascript">
$("#Text2").click(function (e) {
	var ths = this;
	calendar.show({
		id: this, ok: function () {
			//alert(ths.value);
		}
	});
});
</script>            
<script>
//获取上传按钮
var input1 = document.getElementById("upload"); 
 
if(typeof FileReader==='undefined'){ 
     //result.innerHTML = "抱歉，你的浏览器不支持 FileReader"; 
     input1.setAttribute('disabled','disabled'); 
}else{ 
     input1.addEventListener('change',readFile,false); 
     /*input1.addEventListener('change',function (e){
     	console.log(this.files);//上传的文件列表
     },false); */
}
function readFile(){ 
	var file = this.files[0];//获取上传文件列表中第一个文件
	if(!/image\/\w+/.test(file.type)){
	//图片文件的type值为image/png或image/jpg
		alert("文件必须为图片！");
		return false; 
	} 
	// console.log(file);
	var reader = new FileReader();//实例一个文件对象
	reader.readAsDataURL(file);//把上传的文件转换成url
	//当文件读取成功便可以调取上传的接口
	reader.onload = function(e){ 
		// console.log(this.result);//文件路径
		// console.log(e.target.result);//文件路径
		/*var data = e.target.result.split(',');
		var tp = (file.type == 'image/png')? 'png': 'jpg';
		var imgUrl = data[1];//图片的url，去掉(data:image/png;base64,)
		//需要上传到服务器的在这里可以进行ajax请求
		// console.log(imgUrl);
		// 创建一个 Image 对象 
		var image = new Image();
		// 创建一个 Image 对象 
		// image.src = imgUrl;
		image.src = e.target.result;
		image.onload = function(){
			document.body.appendChild(image);
		}*/

		var image = new Image();
		// 设置src属性 
		image.src = e.target.result;
		var max=200;
		// 绑定load事件处理器，加载完成后执行，避免同步问题
		image.onload = function(){ 
			// 获取 canvas DOM 对象 
			var canvas = document.getElementById("cvs"); 
			// 如果高度超标 宽度等比例缩放 *= 
			/*if(image.height > max) {
				image.width *= max / image.height; 
				image.height = max;
			} */
			// 获取 canvas的 2d 环境对象, 
			var ctx = canvas.getContext("2d"); 
			// canvas清屏 
			ctx.clearRect(0, 0, canvas.width, canvas.height); 
			// 重置canvas宽高
			/*canvas.width = image.width;
			canvas.height = image.height;
			if (canvas.width>max) {canvas.width = max;}*/
			// 将图像绘制到canvas上
			// ctx.drawImage(image, 0, 0, image.width, image.height);
			ctx.drawImage(image, 0, 0, 250, 150);
			// 注意，此时image没有加入到dom之中
		};  
	}
};
</script>
<script>
	$(document).ready(function(){

		<?php  if(!empty($member['loc_province'])){?>
		var province = "<?= $member['loc_province'] ?>";
		var city = "<?= $member['loc_city'] ?>";
		var area = "<?= $member['loc_town'] ?>";
		<?php }else{ ?>
		var province = "省 必选";
		var city =  "市 必选";
		var area =  "区 必选";
		<?php } ?>
		var pcas = new PCAS("province,"+province,"city,"+city,"area,"+area);
	});
</script>


